/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.LoginAdminBean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apt.connectDB.MyConnect;

/**
 *
 * @author MinhThang
 */
public class login_admin_bean extends org.apache.struts.action.ActionForm {

    private String txtUserName;
    private String txtPassword;
    private String status;
    public login_admin_bean() {
        super();
        // TODO Auto-generated constructor stub
    }
    public boolean LoginAdmin(String user,String pass,String status){
        //Login admin and manage
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            //admin
            conn=MyConnect.getConnection();
            if(status.equalsIgnoreCase("Admin")){
                String sql="select*from Admin where UserName=? and Password=?";
                ps=conn.prepareCall(sql);
                ps.setString(1, user);
                ps.setString(2, pass);
                rs=ps.executeQuery();
                if(rs.next()){
                    return  true;
                }
                //manage
            }else if(status.equalsIgnoreCase("Manager")){
                String sql="select*from Manager where UserName=? and Password=?";
                ps=conn.prepareCall(sql);
                ps.setString(1, user);
                ps.setString(2, pass);
                rs=ps.executeQuery();
                if(rs.next()){
                    return  true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    

    /**
     * @return the txtUserName
     */
    public String getTxtUserName() {
        return txtUserName;
    }

    /**
     * @param txtUserName the txtUserName to set
     */
    public void setTxtUserName(String txtUserName) {
        this.txtUserName = txtUserName;
    }

    /**
     * @return the txtPassword
     */
    public String getTxtPassword() {
        return txtPassword;
    }

    /**
     * @param txtPassword the txtPassword to set
     */
    public void setTxtPassword(String txtPassword) {
        this.txtPassword = txtPassword;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }
}
